<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_certification".
 *
 * @property int $id
 * @property int $uid 用户
 * @property int $type 类型
 * @property int $status 状态
 * @property string $real_name 真实姓名
 * @property string $id_card 身份证号
 * @property string $phone 电话号码
 * @property string $token
 * @property int $img 认证图片
 * @property string $notify 认证回执
 * @property int $created_at 创建时间
 * @property int $updated_at 最后修改时间
 *
 * @property Image $img0
 * @property User $u
 */
class UserCertification extends \yii\db\ActiveRecord
{

    const PERSONAL_TYPE = 1;
    const BUSINESS_TYPE = 2;

    const ERROR_STATUS = 20;
    const SUCCESS_STATUS = 10;
    const WAIT_STATUS = 0;




    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'user_certification';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'type'], 'required'],
            [['uid', 'type', 'status', 'img', 'created_at', 'updated_at'], 'integer'],
            [['real_name', 'id_card', 'phone', 'token', 'notify'], 'string', 'max' => 255],
            [['img'], 'exist', 'skipOnError' => true, 'targetClass' => Image::className(), 'targetAttribute' => ['img' => 'id']],
            [['uid'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['uid' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '用户',
            'type' => '类型',
            'status' => '状态',
            'real_name' => '真实姓名',
            'id_card' => '身份证号',
            'phone' => '电话号码',
            'token' => 'Token',
            'img' => '认证图片',
            'notify' => '认证回执',
            'created_at' => '创建时间',
            'updated_at' => '最后修改时间',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getImg0()
    {
        return $this->hasOne(Image::className(), ['id' => 'img']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getU()
    {
        return $this->hasOne(User::className(), ['id' => 'uid']);
    }
}
